Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

309
Vistas
JavaScript - Date function throwing "is not a function" error

I am very new to JavaScript and it took me some time to come up with the following function in order to get current date and subtract a year from it:

function getDate() {
    var now = new Date();
    // get current timezone specific date/time
    // timezoneoffset value converts returned offset value to milliseconds
    // get current date value - 1 year
    var dateMinusOneYear = new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);
    var dateStr =
        ("0000" + (dateMinusOneYear.getFullYear())).slice(-4) + "-" +
        ("00" + (dateMinusOneYear.getMonth() + 1)).slice(-2) + "-" +
        ("00" + dateMinusOneYear.getDate()).slice(-2);
    return (dateStr);
}

When I invoke the function, I get the following error: TypeError: dateMinusOneYear.getFullYear is not a function

Can anyone please advise? Some might advise to not use the new Date method at all due to problematic reasons, but I have to use it specifically for some unrelated reasons.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This makes no sense at all

 new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);

Maybe you were trying to accomplish this?

   new Date(now.getTime() - 31556952000 + now.getTimezoneOffset() * 60000);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda